import Mock from 'mockjs'
const data1 = Mock.mock({
    'data|50': [{
        'id|+1': 1,
        'kind|1': ['口腔专家', '骨科专家', '妇科专家', '儿童专家',],
        'hospital': '@ctitle()医院',
        'position|1': ['主任医师', '副主任医师'],
        'kinds|1': ['抗疫专区', '健康养生', '医疗动态', '育儿专区'],
        'name': '@cname(3)医生',
        'image': '@dataImage',
        'desc': '@csentence(500)',
        'text': '@csentence(10)',
        'evaluate|1': ['评价', '环境', '医资'],
        'disease|1': ['神经病', '脑血栓', '高血压']
    }]
})
Mock.mock('/sayinfo', 'post', (config) => {
    let data = data1.data.filter((item: { kinds: any }) => item.kinds === JSON.parse(config.body).kind)
    return data
})

Mock.mock('/sayinfodetail', 'post', (config) => {
    let data = data1.data.filter((item: { id: any }) => item.id === JSON.parse(config.body).id)
    return data
})
// 医生列表信息
Mock.mock('/getdoctorlist', 'post', (config) => {
    let data = {}
    function deepCope(data: { [x: string]: any }, data1: { [x: string]: any }) {
        for (let key in data1) {
            if (Object.prototype.toString.call(key) === '[object Object]') {
                data[key] = {}
                deepCope(data[key], data1[key])
            } else if (Object.prototype.toString.call(key) === '[object Object]') {
                data[key] = []
                deepCope(data[key], data1[key])
            } else {
                data[key] = data1[key]
            }
        }
    }
    deepCope(data, data1)

    if (config.body === '{}' || (config.body === '{"kind":"科室"}' && config.body === '{"evaluate":"综合分类"}')) return data = data1.data
    let body = JSON.parse(config.body)
    
    for (let k in body) {
        if (k === 'kinds') {
            if (body[k] !== '科室') {
                data.data = data.data.filter((item: { kind: any }) => item.kind === body.kinds)                
            }
        }
        if (k === 'evaluate') {
            if (body[k] !== '综合分类') {
                data.data = data.data.filter((item: { evaluate: any }) => item.evaluate === body.evaluate)
            }
        }
        if (k === 'disease') {
            if (body[k] !== '疾病') {
                // console.log(body[k]);
                // console.log(data);
                data.data = data.data.filter((item: { disease: any }) => item.disease === body.disease)
            }
        }
    }    
    return data
})

// 获取预约信息
Mock.mock('/reservationinfo', 'post', (config) => {
    let data = data1.data.filter((item: { id: any }) => item.id === JSON.parse(config.body).id)
    return data
})

